@extends('admin.layouts.app')

@section('right-content')

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>新增邮件</legend>
    </fieldset>

    <form class="layui-form" action="" style="margin-right: 60%">
        <div class="layui-form-item">
            <label class="layui-form-label">发布时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" lay-verify="required" name="published_at" id="published_at" placeholder="请输入发布时间" readonly="">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">收件人</label>
            <div class="layui-input-block">
                <select name="receiver_account_id" >
                    <option value="0">所有人</option>
                    <option value="-1">贵宾玩家</option>
                    <option value="-2">休闲玩家</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>



        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" lay-verify="content" class="layui-textarea" name="content" id="content" style="display: none"></textarea>
            </div>
        </div>

        {{-- <div class="layui-form-item" >
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="enable" value="1" title="上线" checked>
                <input type="radio" name="enable" value="0" title="下线">
            </div>
        </div> --}}


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="sub" data-url="{{ route('emails.store') }}">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
@endsection

@section('my-js')
<script type="text/javascript">
   layui.use(['form', 'laydate', 'layedit'], function(){
       var form = layui.form, laydate = layui.laydate, layedit = layui.layedit;

       var start = laydate.render({
            elem: '#published_at',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            calendar: true,
       });

       var index = layedit.build('content', {
            'height': 180,
            'uploadImage': {
                'url': '',
                'type': 'POST'
            }
       });

       form.verify({
            content : function(value) {
                layedit.sync(index);//用于同步编辑器内容到textarea，异步提交
            }
       });


        form.on('submit(sub)', function(data){
            var url = $(this).attr('data-url');
            commonAjaxSubmit(url, 'POST');
        })
    });
</script>
@endsection

